import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	/*
	 * . # S E
	 */
	static char[][][] lab;

	static Queue<int[]> fila;

	static char MARCADO = 'M';
	static char PAREDE = '#';
	static char LIVRE = '.';

	static int x1, y1, z1;

	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);

		while (scan.hasNext()) {

			int l = (Integer.parseInt(scan.next()));
			int r = (Integer.parseInt(scan.next()));
			int c = (Integer.parseInt(scan.next()));

			x1 = l;
			y1 = r;
			z1 = c;

			int l_ini = 0, r_ini = 0, c_ini = 0;
			lab = new char[l][r][c];
			if (l == c && c == r && r == 0) {
				break;
			}
			for (int altura = 0; altura < l; altura++) {
				int linha = 0;
				while (linha < r) {
					String strlinha = scan.next();
					for (int coluna = 0; coluna < c; coluna++) {
						lab[altura][linha][coluna] = strlinha.charAt(coluna);
						if (strlinha.charAt(coluna) == 'S') {
							l_ini = altura;
							r_ini = linha;
							c_ini = coluna;
						}
					}
					linha++;
				}
				scan.nextLine();
			}

			executar(l_ini, r_ini, c_ini);

			// System.out.println("Escaped in "+menorCaminho+" minute(s).");
			// System.out.println("Trapped!");
		}
	}

	static void executar(int x, int y, int z) {

		fila = new LinkedList<int[]>();
		fila.add(new int[] { x, y, z, 0 });
		lab[x][y][z] = MARCADO;

		while (!fila.isEmpty()) {

			int[] temp = fila.remove();
//			System.out.println("Desempilha \t" + temp[0] + " " + temp[1] + " " + temp[2]);

			try {
				enfilera(temp[0] + 1, temp[1], temp[2], temp);
				enfilera(temp[0] - 1, temp[1], temp[2], temp);
				enfilera(temp[0], temp[1] + 1, temp[2], temp);
				enfilera(temp[0], temp[1] - 1, temp[2], temp);
				enfilera(temp[0], temp[1], temp[2] + 1, temp);
				enfilera(temp[0], temp[1], temp[2] - 1, temp);
			} catch (Exception e) {
				return;
			}
		}

		System.out.println("Trapped!");
	}

	private static void enfilera(int x, int y, int z, int[] temp) throws Exception {
	
		if (posicaoValida(x, y, z)) {

			if (lab[x][y][z] == 'E') {
				System.out.println("Escaped in " + (temp[3] + 1) + " minute(s).");
				throw new Exception();
			}

			if (lab[x][y][z] == LIVRE) {
				fila.add(new int[] { x, y, z, temp[3] + 1 });
//				System.out.println("Empilha \t" + x + " " + y + " " + z);
				lab[x][y][z] = MARCADO;
			}
		}
	}

	private static boolean posicaoValida(int x, int y, int z) {

		boolean horizontal = (x < x1 && x >= 0);
		boolean vertical = (y < y1 && y >= 0);
		boolean altura = (z < z1 && z >= 0);

		if (horizontal && vertical && altura) {

			boolean naoParede = (lab[x][y][z] != PAREDE);

			if (naoParede) {
				return true;
			}

		}

		return false;
	}

}

/*
 * ENTRADA:
 * 
 * 3 4 5 S.... .###. .##.. ###.#
 * 
 * ##### ##### ##.## ##...
 * 
 * ##### ##### #.### ####E
 * 
 * 1 3 3 S## #E# ###
 * 
 * 0 0 0
 * 
 * 
 * SAIDA:
 * 
 * Escaped in 11 minute(s). Trapped!
 */
